home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-config-printer / XmlHelper.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  2.5 KB  |  69 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import libxml2
  6. from debug import *
  7.  
  8. class XmlHelper(object):
  9.     
  10.     def __init__(self, filename):
  11.         self.group_file_name = None
  12.         self.xml_doc = None
  13.         self.group_file_name = filename
  14.         if not os.path.exists(self.group_file_name):
  15.             
  16.             try:
  17.                 self.xml_doc = libxml2.newDoc('1.0')
  18.                 self.xml_doc.setRootElement(libxml2.newNode('ospm-groups'))
  19.                 self.xml_doc.saveFormatFile(self.group_file_name, True)
  20.             nonfatalException()
  21.  
  22.         else:
  23.             
  24.             try:
  25.                 self.xml_doc = libxml2.parseFile(self.group_file_name)
  26.             except:
  27.                 nonfatalException()
  28.  
  29.  
  30.     
  31.     def write(self):
  32.         if self.xml_doc.saveFormatFile(self.group_file_name, True) == -1:
  33.             nonfatalException()
  34.         
  35.  
  36.     
  37.     def __get_non_text_child(self, node):
  38.         child = node.children
  39.         while child and child.isText:
  40.             child = child.next
  41.         return child
  42.  
  43.     
  44.     def __parse_groups(self, key):
  45.         current = self.xml_doc.getRootElement().children
  46.         group_list = []
  47.         while current:
  48.             if current.name == key:
  49.                 group_list.append((current.prop('name'), current))
  50.             
  51.             current = current.next
  52.         return group_list
  53.  
  54.     
  55.     def get_static_groups(self):
  56.         return self._XmlHelper__parse_groups('static-group')
  57.  
  58.     
  59.     def get_search_groups(self):
  60.         return self._XmlHelper__parse_groups('search-group')
  61.  
  62.     
  63.     def add_group(self, group_node):
  64.         self.xml_doc.getRootElement().addChild(group_node)
  65.         self.write()
  66.  
  67.  
  68. xml_helper = XmlHelper(os.path.expanduser('~/.printer-groups.xml'))
  69.